<template>
  <div class="icons-wrapper">
    <div>
      <swiper :options="swiperOption" v-if="isIconShow">
        <swiper-slide v-for="(page, idx) in pages" :key="idx">
          <div class="icon-box"
               v-for="item in page" :key="item.id">
            <div class="icon-box-img">
              <img class="icon-img" :src="item.imgUrl"/>
            </div>
            <p class="icon-desc">{{item.description}}</p>
          </div>
        </swiper-slide>
      </swiper>
    </div>
  </div>
</template>

<script>
export default {
  name: "HomeIcons",
  props: {
    iconsList: Array
  },
  data() {
    return {
      swiperOption: {
        loop: true,
        autoplay: false
      }
    }
  },
  computed: {
    pages: function(){
      var pages = [];
      this.iconsList.forEach(function(item, idx){
        var page = Math.floor(idx / 8);
        if(!pages[page]){
          pages[page] = [];
        }
        pages[page].push(item);
      })
      return pages;
    },
    isIconShow: function(){
      return this.iconsList.length;
    }
  }
};
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl';
@import '~styles/mixins.styl';

.icons-wrapper {
  width: 100%;
  height: 0;
  padding-bottom: 50%;
  overflow hidden
  margin .2rem 0
}

.icons-wrapper .icon-box {
  position: relative;
  float: left;
  width: 25%;
  height: 0;
  padding-bottom: 25%;
  // background-color: red;
}

.icons-wrapper .icon-box .icon-box-img {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0.44rem;
  // background-color: blue;
}

.icons-wrapper .icon-box .icon-box-img img {
  display: block;
  margin: 0 auto;
  height: 100%;
}

.icons-wrapper .icon-box .icon-desc {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0.44rem;
  line-height: 0.44rem;
  text-align: center;
  color: $darTextColor;
  ellipsis()
}
</style>